package com.jackrain.nea.fc.pos.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wuwenxue
 * @date 2018/05/22
 **/
@Mapper
public interface ViewDLStoreBillToF4Mapper {

    @Select("select b.BILL_NO from DL_B_RETAIL_C_STORE a ,dl_b_retail b " +
            "where a.dl_b_retail_id = b.id and a.dl_b_store_bill_no = #{billno}")
    List<HashMap> selRetailStoreData(@Param("billno") String billno);

    @SelectProvider(type = ViewDLStoreBillSql.class, method = "findStoreBillData")
    List<HashMap> selStoreBillData(@Param("id") Object[] id);

    @SelectProvider(type = ViewDLStoreBillSql.class, method = "findStoreBillItemData")
    List<HashMap> selStoreBillItemData(@Param("id") Long id);

    class ViewDLStoreBillSql {

        public String findStoreBillData(Map<String, Object> map) {
            Object[] id = (Object[]) map.get("id");
            return new SQL() {
                {
                    SELECT("ID,BILL_NO,BILL_DATE,CP_C_STORE_ID,ACCEPTERDATE,STATUS,CREATIONDATE," +
                            "OWNERENAME,MODIFIEDNAME,MODIFIEDENAME,MODIFIEDDATE,ACCEPTERENAME");
                    FROM("DL_B_STORE_BILL");
                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < id.length; i++) {
                        sb.append(id[i] + ",");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    WHERE("ID IN (" + sb.toString() + ")");
                }
            }.toString();
        }


        public String findStoreBillItemData(Map<String, Object> map) {
            Long id = (Long) map.get("id");
            return new SQL() {
                {
                    SELECT("MONEY,BANKCARD,WECHAT,ALIPAY,SHOPCARD,BILL_NO");
                    FROM("DL_B_STORE_BILL_ITEM");
                    WHERE("DL_B_STORE_BILL_ID =" + id);
                }
            }.toString();
        }
    }


}
